package com.erp.service.util.net;

import java.io.IOException;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.protocol.HttpContext;
/**
 * Gzip请求拦截器
 * @author ccl
 *
 */
class GzipRequestInterceptor implements HttpRequestInterceptor
{
        static private final GzipRequestInterceptor instance = new GzipRequestInterceptor();
        
        /**
         * 拦截请求，加入接受gzip的httpheader
         */
        public void process(
                final HttpRequest request, 
                final HttpContext context) throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }
        }

        /**
         * 获取拦截器单例
         * @return
         */
        static public GzipRequestInterceptor getInstance()
        {
                return instance;
        }
}
